package com.api.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.api.dao.ProjectMapper;
import com.api.entity.Project;
import com.api.service.ProjectService;

@Service
public class ProjectServiceImpl implements ProjectService{
	
	@Autowired
	private ProjectMapper projectMapper;

	@Override
	public int add(Project project) {
		project.preInsert();
		return this.projectMapper.insert(project);
	}

	@Override
	@Cacheable(value="api",key="#id")
	public Project getProject(String id) {
		return this.projectMapper.selectByPrimaryKey(id);
	}

	@Override
	@Cacheable(value="api")
	public List<Project> getProjectList(Project project) {
		return this.projectMapper.findList(project);
	}

	@Override
	public int deleteProject(Project project) {
		return this.projectMapper.update(project);
	}

	@Override
	@CachePut(value="api",key="#project.id")
	public int updateProject(Project project) {
		return this.projectMapper.update(project);
	}

	@Override
	@Cacheable(value="api",key="#id")
	public Project getProjectById(String id) {
		return this.projectMapper.selectByPrimaryKey(id);
	}


}
